package com.gdth.widget.edittext.listener;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.gdth.widget.dialog.BaseToast;

/**
 * edittext值改变监听
 * @author mac1
 *
 */
public class TextWatcherListener implements TextWatcher {
	private int length;
	private EditText mEditText;
	private Context context;
	
	public TextWatcherListener(Context context, EditText mEditText, int length) {
		this.context = context;
		this.mEditText = mEditText;
		this.length = length;
	}
	
	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before,
			int count) {
		// TODO Auto-generated method stub
		if (s.length() > length) {
			BaseToast.getInstance().ShowSystemToast(context, "长度超过" + length);
			mEditText.setText(s.subSequence(0, length));
			mEditText.setSelection(length);
		}
	}

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub
		
	}

}
